<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实验4</title>
</head>

<body>
   
    <script>
        function getSum() {
            var sum = 0;
            for (var i in arguments) {
                sum += arguments[i];
            }
            return sum;
        }
        console.log(getSum(10, 20, 30));
    </script>
    <br>
    2. 网页计算器
    <p>输入数字：<input id="num1" type="text"></p>
    <p>输入数字：<input id="num2" type="text"></p>
    <p>
        <input type="button" value="+" onclick="calc(add)">
        <input type="button" value="-" onclick="calc(sub)">
        <input type="button" value="*" onclick="calc(mul)">
        <input type="button" value="/" onclick="calc(div)">
    </p>
    <p>结果：<input type="text" id="result" readonly></p>
    <script>
    function calc(func){
        var result=document.getElementById('result');
        var num1=parseInt(document.getElementById('num1').value);
        var num2=parseInt(document.getElementById('num2').value);
        if(isNaN(num1)||isNaN(num2)){
            alert('输入一个数字');
            return false;
        }
        result.value=func(num1,num2);
    }
    function add(num1,num2){
        return num1+num2;
    }
    function sub(num1,num2){
        return num1-num2;
    }
    function mul(num1,num2){
        return num1*num2;
    }
    function div(num1,num2){
        if(num2===0){
            alert('除数不为0');
            return'';
        }
        return num1/num2;
    }
    </script>

    3. 编写函数实现单击change按钮，为div元素添加红色双线边框。
    <style>
            div{ width:500px; height: 500px; border:1px solid;}
        </style>
        <div></div>
        <p> <button id="btn">改变</button> </p>
        <script>
            var btn = document.getElementById('btn');
            var div = document.getElementsByTagName('div')[0];
            btn.onclick = function () {
                div.style.border = 'double red';
            }
        </script>
        



</body>

</html>